package com.example.administrator.fishbone.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.fishbone.R;
import com.example.administrator.fishbone.utils.LinkmanUtils;

import java.util.ArrayList;
import java.util.List;

import it.sephiroth.android.library.util.ViewHelperFactory;

/**
 * Created by ${杨文超} on 2016/9/2.
 */
public class LinkmanAdapter extends BaseAdapter {
    List<LinkmanUtils> list = new ArrayList<>();
    private LayoutInflater inflater;
    public LinkmanAdapter(Context context,List<LinkmanUtils> list) {
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return null == list ? 0 : list.size();
    }

    @Override
    public LinkmanUtils getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
Viewholder viewholder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.personnel_list_item, parent, false);
            viewholder = new Viewholder(convertView);
            viewholder.textName = (TextView) convertView.findViewById(R.id.person_item_TextName);
            viewholder.textLast = (TextView) convertView.findViewById(R.id.person_item_Texticon);
        } else {
            viewholder = (Viewholder) convertView.getTag();
        }
        LinkmanUtils utils = getItem(position);
        String name = utils.getTVname();
        viewholder.textName.setText(utils.getTVname());
        if (!TextUtils.isEmpty(name)) {
            int len = name.length();
            String iconText = name.substring(len - 1, len);
            viewholder.textName.setText(name);
            viewholder.textLast.setText(iconText);

        } else {
            viewholder.textName.setText("");
        }
        return convertView;
    }
    private static class Viewholder{
        TextView textName;
        TextView textLast;

        public Viewholder(View convertView) {
            if (convertView != null) {
                convertView.setTag(this);
            }
        }
    }
}
